import java.awt.Color;
import java.util.Random;
import java.awt.Graphics;


public class Ball 
{
	
	int x, y;
	double xSpeed, ySpeed;
	double velocityX;
	double velocityY;
	
	double maxXSpeed = 10;
	double maxYSpeed = 10;
	
	public Ball(int x, int y)
	{
		this.x = x;
		this.y = y;
		
		this.xSpeed = 0;
		this.ySpeed = 1;
		
		this.velocityX = 0.0;
		this.velocityY = 0.1;
	}
	
	/** Called every time game ticks. Used for: movement & collision */
	public void tick()
	{
		//Movement
		xSpeed -= velocityX;
		ySpeed -= velocityY;
		
		if(xSpeed < maxXSpeed || -xSpeed > -maxXSpeed) x += xSpeed;
		else xSpeed = maxXSpeed;
		if(ySpeed < maxYSpeed || -ySpeed > -maxYSpeed) y += ySpeed;
		else ySpeed = maxYSpeed;
		
		/*
		x += xSpeed;
		y += ySpeed;
		*/
		
		//Check for off the screen
		
		if(x <= 0)
		{
			xSpeed *= -1;
			velocityX *= -1;
			System.out.println("Hit the X Bounds");
		}
		if(y <= 0 || y >= Pong.YSIZE)
		{
			ySpeed *= -1;
			velocityY *= -1;
			System.out.println("Hit the Y Bounds");
		}
	}
	
	public void render(Graphics g)
	{
		g.setColor(Color.GREEN);
		g.fillOval(x, y, 20, 20);
	}
}
